package com.sx.utils;

import java.util.Random;
import java.util.UUID;

/**
 * @author AdinZ
 * @date 2020/11/7 11:31
 */
public class RandomUtils {
    /**
     * 生成指定范围随机数字
     * @param min
     * @param max
     * @return
     */
    public static int randomInt(int min,int max){
        int s = new Random().nextInt(max) % (max - min + 1) + min;
        return s;
    }
    /**
     * 生成一个随机数字
     * @param i
     * @return
     */
    public static int randomInt(int i){
        return new Random().nextInt(i);
    }
    /**
     * 随机选择一个数字
     * @param ints
     * @return
     */
    public static int choice(int[] ints){
        int size=ints.length;
        int i=randomInt(size);
        return ints[i];
    }
    public static String randomStr(int length) {
        String chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
        int maxPos = chars.length();
        String pwd = "";
        for (int i = 0; i < length; i++) {
            char c = chars.charAt((int) Math.floor(Math.random() * maxPos));
            pwd += String.valueOf(c);
        }
        return pwd;
    }
    public static String randomUUID() {
        return UUID.randomUUID().toString();
    }
    public static long randomSnowflake(){
        return SnowflakeIdWorker.generateId();
    }
    public static String randomSnowflake(String prefix){
        return new StringBuffer(prefix).append("-").append(randomSnowflake()).toString();
    }
}
